#include <cstdio>
#include <ctime>
#include <filesystem>
#include <fmt/format.h>
#include <iostream>
// manipulator
using namespace std;
using namespace filesystem;

void printDirectoryStructure(const path &p) {
  if (!exists(p)) {
    return;
  }

  recursive_directory_iterator begin{p};
  recursive_directory_iterator end{};
  for (auto iter{begin}; iter != end; ++iter) {
    const string spacer(iter.depth() * 2, ' ');
    auto entry{*iter};
    if (is_regular_file(entry)) {
      cout << fmt::format("{}File: {}({} bytes)", spacer, entry.path().string(),
                          file_size(entry))
           << endl;

    } else if (is_directory(entry)) {
      cout << fmt::format("{}Dir: {}", spacer, entry.path().string()) << endl;
    }
  }
}

void printDirectoryStructure(const path &p, size_t level = 0) {
  if (!exists(p)) {
    return;
  }

  const string spacer(level * 2, ' ');

  if (is_regular_file(p)) {
    cout << fmt::format("{}File: {}({} bytes)", spacer, p.string(),
                        file_size(p))
         << endl;

  } else if (is_directory(p)) {
    cout << fmt::format("{}Dir: {}", spacer, p.string()) << endl;
    for (auto &entry : directory_iterator(p)) {
      printDirectoryStructure(entry, level + 1);
    }
  }
}

int main() {
  path mypath{"C:/windows/win.ini"};
  directory_entry entry{mypath};

  if (entry.exists()) {
    if (entry.is_directory()) {
      std::cout << "It's a directory." << std::endl;
    } else if (entry.is_regular_file()) {
      std::cout << "It's a regular file." << std::endl;
    }
  } else {
    std::cout << "The path does not exist." << std::endl;
  }
}